@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="{{url('css/admin/jquery-ui.css')}}">
    <script type="text/javascript" src="{{url('css/admin/jquery-ui.min.js')}}"></script>
    <link href="{{url('js/lib/jquery-ui-timepicker-addon.css')}}" type="text/css" />
    <script src="{{url('js/lib/jquery-ui-timepicker-addon.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery.ui.datepicker-zh-CN.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery-ui-timepicker-zh-CN.js')}}" type="text/javascript"></script>

    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')
    <!-- content start -->

    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">活动管理</a>
            <em>></em>
            <a href="{{route('Admin.Home.bargainList')}}">砍价活动列表</a>
            <em>></em>
            <a href="#">砍价活动设置</a>
        </div>

        @include('admin.common.activity-header')

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="bargainid" value="@if($thisActivityBargain && $thisActivityBargain->id){{$thisActivityBargain->id}} @endif"/>
                <div class="gg-list">
                    <label class="tit">商品编号</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品货号" name="ssn" id="ssn" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->ssn}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入1-20个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">商品名称</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入商品名称" name="name" id="name" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->name}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入1-50个字符(一个汉字等于两个字符)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">市场价格</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入市场价格" name="m_price" id="m_price" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->m_price}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">销售价格</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入销售价格" name="s_price" id="s_price" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->s_price}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>

                <div class="gg-list" data-id="ggzst2">
                    <label class="tit">商品封面图</label>
                    <div class="demo" style="display: inline-block; padding: 0; margin: 0; *display: inline; *zoom:1;">
                        <input type = "hidden" name = "pic_img" id = "pic_img2" value = "" height="70px" >
                        <div id="showimg">
                        </div>
                        <div class="btn" style="background: #00A2D4">
                            <span id="inputImage">添加图片</span>
                            <input id="img_id" type="hidden" name="thumb_id" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->thumb_id}} @endif">
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span >
                        </div>
                        <p class="text" id="uploadthumb">上传详情图（图片格式为jpg、png、gif，规格：高限315px,文件小于2MB）</p>
                        @if($thisActivityBargain && $thisActivityBargain->goods_info && $thisActivityBargain->goods_info->thumb_id != 0)<img id="img_show" style="width: 100px;padding-top: 3px;" src="{{\App\Http\Services\FileManager::getImgUrl($thisActivityBargain->goods_info->thumb_id)}}" />@endif

                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">是否包邮</label>
                    <div class="cont">
                        <select name="is_free_shipping" id="is_free_shipping">
                            <option value="0" @if($thisActivityBargain && $thisActivityBargain->goods_info && $thisActivityBargain->goods_info->is_free_shipping == 0) selected @endif>不包邮</option>
                            <option value="1" @if($thisActivityBargain && $thisActivityBargain->goods_info && $thisActivityBargain->goods_info->is_free_shipping == 1) selected @endif>包邮</option>
                        </select>
                        <p class="text"></p>
                    </div>
                </div>

                <div class="gg-list" data-id="ggwz">
                    <label class="tit">商品信息：</label>
                    <div class="cont">
                        <textarea placeholder="请输入商品信息" name="info" id="info" cols="70" rows="10">@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->info}} @endif</textarea>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">积分</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入购买商品所获的积分数量" name="integral" id="integral" value="@if($thisActivityBargain && $thisActivityBargain->goods_info){{$thisActivityBargain->goods_info->integral}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(注意是整数)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">活动开始时间</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入活动开始时间" name="start_time" id="start_time" value="@if($thisActivityBargain){{$thisActivityBargain->start_time}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">选择时间</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">活动结束时间</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入活动结束时间" name="end_time" id="end_time" value="@if($thisActivityBargain){{$thisActivityBargain->end_time}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">选择时间</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">砍价最大金额</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入砍价最大金额" name="max_money" id="max_money" value="@if($thisActivityBargain){{$thisActivityBargain->max_money}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(小数或整数)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">最大参与人数</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入最大参与人数" name="max_join_count" id="max_join_count" value="@if($thisActivityBargain){{$thisActivityBargain->max_join_count}} @endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">输入数值(整数)</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">活动状态</label>
                    <div class="cont">
                        <select name="status" id="status">
                            <option value="1" @if($thisActivityBargain && $thisActivityBargain->status == 1) selected @endif>上架</option>
                            <option value="0" @if($thisActivityBargain && $thisActivityBargain->status == 0) selected @endif>下架</option>
                        </select>
                        <p class="text">选择上架或下架 ( 默认上架 )</p>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>





    <!-- content end -->
    <script>
        $(function() {

            jQuery('#start_time').datetimepicker({
                timeFormat: "HH:mm:ss",
                dateFormat: "yy-mm-dd",
                beforeShow: function () {
                    setTimeout(
                        function () {
                            $('#ui-datepicker-div').css("z-index", 1000);
                        }, 100
                    );
                }
            });

            jQuery('#end_time').datetimepicker({
                timeFormat: "HH:mm:ss",
                dateFormat: "yy-mm-dd",
                beforeShow: function () {
                    setTimeout(
                            function () {
                                $('#ui-datepicker-div').css("z-index", 1000);
                            }, 100
                    );
                }
            });

            $(document).on('click', '#btn-set', function () {
                var info         = $('#info').val();
                var ssn          = $('#ssn').val();
                var name         = $('#name').val();
                var mPrice       = $('#m_price').val();
                var sPrice       = $('#s_price').val();
                var imgId        = $('#img_id').val();
                var isFreeShipping=$('#is_free_shipping option:selected').val();
                var integral     = $("#integral").val();
                var startTime    = $('#start_time').val();
                var endTime      = $('#end_time').val();
                var maxMoney     = $('#max_money').val();
                var maxJoinCount = $('#max_join_count').val();
                var status       = $('#status').val();
                var id           = $('#bargainid').val();

                $.ajax({
                    url: '{{route("Api.Admin.activity.setActivityBargain")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        ssn:ssn,
                        name:name,
                        m_price:mPrice,
                        s_price:sPrice,
                        thumb_id:imgId,
                        info:info,
                        isFreeShipping:isFreeShipping,
                        integral:integral,
                        id:id,
                        type:"bargain",
                        start_time:startTime,
                        end_time:endTime,
                        max_money:maxMoney,
                        max_join_count:maxJoinCount,
                        status:status
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href = "{{route('Admin.Home.bargainList')}}";
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            //缩略图上传代码
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{route("Api.File.upload")}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '20mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {},

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {
                        $('#uploadthumb').html('<span style="color:red">上传中...</span>');
                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        if (responseObj.level == "success") {
                            $('#img_id').val(responseObj.data.id);
                            var imgURL = responseObj.data.img_url + "?" + Math.random();
                            $('#img_show').attr("src",imgURL);
                            $('#uploadthumb').html('<span style="color:green">上传成功</span>');
                        } else {
                            noty({type: responseObj.level, text: responseObj.message, timeout: 800});
                            $('#uploadthumb').html('<span style="color: red">上传失败，请重新上传！</span>');
                        }

                    }
                }
            });
            uploader.init();
        });
    </script>

@endsection